<include file="public@header"/>
<style>
    .cas-thumbnail {
        width: 80px;
        height: 80px;
    }

    .table td, .table th {
        text-align: center;;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('AdminProduct/index')}">所有产品</a></li>
        <li><a href="{:url('AdminProduct/add')}">添加产品</a></li>
        <li><a href="{:url('AdminProduct/import')}">导入产品</a></li>
    </ul>
    <form class="well form-inline margin-top-20" method="post" action="{:url('AdminProduct/index')}">
        CAS：
        <input type="text" class="form-control" name="cas" style="width:100px;" value="{:input('param.cas')}"
               placeholder="请输入CAS">
        &nbsp;&nbsp;&nbsp;关键字：
        <input type="text" class="form-control" name="keyword" style="width: 200px;" value="{:input('param.keyword')}"
               placeholder="请输入化合物名称/分子式">
        &nbsp;&nbsp;&nbsp;<input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger" href="{:url('AdminProduct/index')}">清空</a>
    </form>
    <form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/publish',['yes'=>1])}" data-subcheck="true">上架
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/publish',['no'=>1])}" data-subcheck="true">下架
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/top',['yes'=>1])}" data-subcheck="true">置顶
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/top',['no'=>1])}" data-subcheck="true">取消置顶
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/recommend',['yes'=>1])}" data-subcheck="true">推荐
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/recommend',['no'=>1])}" data-subcheck="true">取消推荐
            </button>
            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/delete')}" data-subcheck="true" data-msg="你确定删除吗？">
                {:lang('DELETE')}
            </button>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15"><label><input type="checkbox" class="js-check-all" data-direction="x"
                                             data-checklist="js-check-x"></label></th>
                <th width="100">CAS</th>
                <th>名称</th>
                <th width="90">结构式</th>
                <th width="130">首次入库</th>
                <th width="70">点击量</th>
                <th width="70">{:lang('STATUS')}</th>
                <th width="120">{:lang('ACTIONS')}</th>
            </tr>
            </thead>
            <php>
                $status=array("1"=>"上架","0"=>"下架");
                $top_status=array("1"=>"置顶","0"=>"");
                $recommend_status=array("1"=>"推荐","0"=>"");
            </php>
            <foreach name="products" item="vo">
                <tr>
                    <td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}"></td>
                    <td><a href="javascript:parent.openIframeLayer('{:url('AdminProduct/packs',array('id'=>$vo['id']))}','产品库存',{});">{$vo.cas}</a></td>
                    <td>
                        <notempty name="vo.cn_name">
                            {$vo.cn_name}
                        </notempty>
                        <br>{$vo.name}
                    </td>
                    <td>
                        <eq name="vo.thumbnail" value="has">
                            <img src="http://www.chemium.cn/chemium/api/getCompoundPng/cas/{$vo.cas}"
                                 class="cas-thumbnail" onerror="javascript:this.style.visibility='hidden';"/><br>
                            <else/>
                            <notempty name="vo.thumbnail">
                                <img src="{:cmf_get_image_preview_url($vo.thumbnail)}" class="cas-thumbnail"
                                     onerror="javascript:this.style.visibility='hidden';"/><br>
                                <else/>
                                <div style="width: 80px;height: 80px;background: #fff;">
                                    <img src="http://www.chemium.cn/chemium/api/getCompoundPng/cas/{$vo.cas}"
                                         class="cas-thumbnail" onerror="javascript:this.style.visibility='hidden';"/>
                                </div>
                            </notempty>
                        </eq>

                        {:sp_beautify_molformula($vo['mol_formula'])}
                    </td>

                    <td>{:date('Y-m-d H:i',$vo['create_time'])}</td>
                    <td>{$vo.hits}</td>
                    <td>{$status[$vo['status']]} {$top_status[$vo['is_top']]} {$recommend_status[$vo['recommended']]}
                    </td>
                    <td>
                        <a href="{:url('AdminProduct/edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a>
                        <a href="{:url('AdminProduct/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                    </td>
                </tr>
            </foreach>
            <tfoot>
            <tr>
                <th width="15"><label><input type="checkbox" class="js-check-all" data-direction="x"
                                             data-checklist="js-check-x"></label></th>
                <th width="90">结构式</th>
                <th width="100">CAS号</th>
                <th>名称</th>
                <th width="130">录入时间</th>
                <th width="70">点击量</th>
                <th width="70">{:lang('STATUS')}</th>
                <th width="120">{:lang('ACTIONS')}</th>
            </tr>
            </tfoot>
        </table>
        <div class="table-actions">
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/publish')}" data-subcheck="true">上架
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/unpublish')}" data-subcheck="true">下架
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/top',array('top'=>1))}" data-subcheck="true">置顶
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/untop',array('untop'=>1))}" data-subcheck="true">取消置顶
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/recommend',array('recommend'=>1))}" data-subcheck="true">推荐
            </button>
            <button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/unrecommend',array('unrecommend'=>1))}" data-subcheck="true">取消推荐
            </button>
            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('AdminProduct/delete')}" data-subcheck="true" data-msg="你确定删除吗？">
                {:lang('DELETE')}
            </button>
        </div>
        <div class="pagination">{$page}</div>
    </form>
</div>
<img id="cas-thumbnail-bigger"
     style="position: fixed;top: 50%;left: 50%;width: 300px;height: 300px;margin-left: -150px;margin-top: -150px;display: none;box-shadow: 0px 0px 20px rgba(0,0,0,0.2);"/>
<script src="__STATIC__/js/admin.js"></script>
<script>
    $(function () {
        var $cas_thumbnail_bigger = $('#cas-thumbnail-bigger');
        $('.cas-thumbnail').hover(function () {
            $cas_thumbnail_bigger.attr('src', $(this).attr('src'));
            $cas_thumbnail_bigger.show();
        }, function () {
            $cas_thumbnail_bigger.hide();
        });
    });

</script>
</body>
</html>